package com.tanhua.server.interceptor;

import com.tanhua.commons.constant.Constants;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Set;

/**
 * @author PengEmperor
 * @date 2021-12-27 20:19
 * 定时删除redis的限制语音次数
 */
@Component
@Slf4j
public class VoiceTask {

    @Autowired
    private StringRedisTemplate redisTemplate;

    /**
     * 配置时间规则
     */
    @Scheduled(cron = "0 0 0 */1 * ?")
    public void disVoiceNum() {
//        Set<String> key1 = redisTemplate.keys(Constants.VOICE + "*");
//        assert key1 != null;
//        redisTemplate.delete(key1);//重置发送语音次数
        Set<String> key2 = redisTemplate.keys(Constants.RECEIVE_VOICE);
        assert key2 != null;
        redisTemplate.delete(key2);//重置接收语音次数
    }
}
